﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using Microsoft.Forums.MicrosoftForumsProvider;
using Microsoft.Forums.SyncService;
using Microsoft.Forums.OfflineStore;
using Microsoft.Forums.ForumsClient.Controllers;
using Microsoft.Forums.ForumsClient.Models;

namespace Microsoft.Forums.ForumsClient
{
    /// <summary>
    /// Interaction logic for SynchSettingsDialog.xaml
    /// </summary>
    public partial class OptionsDialog : Window
    {
        private OptionsDataModel optionsDataModel;
        private OptionsController controller;

        /// <summary>
        /// Constructor sets curor to wait until data is initialized
        /// </summary>
        /// <param name="synchModel"></param>
        public OptionsDialog(OptionsDataModel optionsModel)
        {
            if (optionsModel == null) throw new ArgumentNullException("optionsModel", "optionsModel cannot be null");

            InitializeComponent();

            optionsDataModel = optionsModel;
            controller = new OptionsController(optionsDataModel);
            this.DataContext = optionsDataModel;

        }

        #region Close Command Handlers
        /// <summary>
        /// Handles the dialog's close button click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Close_Executed(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            this.Close();
        }
        #endregion

        #region Finish Command Handler
        /// <summary>
        /// Determines whether or not the command can be executed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveOptionsSettings_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = controller.CanSaveOptionsSettings;
        }

        /// <summary>
        /// Executes code behind dialog's Finish button click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveOptionsSettings_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            controller.SaveOptionsSettings();
            DialogResult = true;
            this.Close();
        }
        #endregion
    }
}
